
//
//  HMVisitorTableViewController.swift
//  Weibo-swift
//
//  Created by GD on 16/9/20.
//  Copyright © 2016年 geduo. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController {
    //是否登录的标识
    var isLogin : Bool = HMUserAccountViewModel.sharedUserAccountViewModel.isLogin
    
    var visitorView : HMVistorView?
    
    //自定义View视图
    override func loadView() {
        if isLogin {
            super.loadView()
        }else{//未登录
            //自己提供一个视图
            visitorView = HMVistorView()
//            visitorView.backgroundColor = UIColor.magenta
//            visitorView?.delegate = self
            visitorView?.loginClosure = {
                print("我是从visitorView闭包调用过来的登录事件")
                
                let nav : HMNavgationViewController = HMNavgationViewController(rootViewController: HMOAuthViewController())
                
                self.present(nav, animated: true, completion: nil)
            }
            view = visitorView
            
            setupNavUI()
        }
    }
    
    private func setupNavUI(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录",  target: self, action: #selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册",  target: self, action: #selector(loginAction))
    }
    
    //MARK: --- 点击事件
    @objc private func loginAction() {//登录和注册执行同一个方法
        print("登录")
        
        let nav : HMNavgationViewController = HMNavgationViewController(rootViewController: HMOAuthViewController())
        
        present(nav, animated: true, completion: nil)
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    
}

extension HMVisitorTableViewController : HMVisitorDelegate{
    func loginBtnClick() {
        print("我是从代理方式调用过来的")
        
        let nav : HMNavgationViewController = HMNavgationViewController(rootViewController: HMOAuthViewController())
        
        present(nav, animated: true, completion: nil)
    }
}
